package logic

import (
	"context"
	"errors"
	"house-info-net/models/mysql"

	"house-info-net/houserpc/houserpc"
	"house-info-net/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *UserShowLogic) UserShow(in *houserpc.UserShowRequest) (*houserpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User
	if err := user.FindUserByUserId(mysql.DB, in.UserId); err != nil {
		return nil, errors.New("用户不存在")
	}
	return &houserpc.UserShowResponse{
		UserId:    int64(user.ID),
		Mobile:    user.Mobile,
		Password:  user.Password,
		HeadImage: user.HeadImage,
		NickName:  user.NickName,
	}, nil
}
